const state = {
  template: {},
  error: {
    title: '发生错误',
    code: 500,
    url: '/',
    message: '',
  },
}

const TEMPLATE_CLEAR = 'TEMPLATE_CLEAR'
const PUSH_ERROR_INFO = 'PUSH_ERROR_INFO'

const actions = {
  // 调用同步操作修改数据
  [TEMPLATE_CLEAR]({ commit }, payload) {
    console.log(payload)
    // 异步操作
    commit(TEMPLATE_CLEAR, payload.user)
  },
  // 前端错误暂存
  [PUSH_ERROR_INFO]({ commit }, payload) {
    console.log('PUSH_ERROR_INFO: ', payload)
    commit(PUSH_ERROR_INFO, payload)
  },
}

const mutations = {
  [TEMPLATE_CLEAR](state, user) {
    console.log('操作', state, user)
    Object.assign(state, user)
  },
  [PUSH_ERROR_INFO](state, error) {
    console.log('PUSH_ERROR_INFO', error)
    Object.assign(state, error)
  },
}

export default {
  state,
  actions,
  mutations,
}
